<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">

	<ui:define name="corpoForm">
		

		<h:form id="formBotoesSituacaoTributaria" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarSituacaoTributaria"
					value="#{rsc.label_criar}" styleClass="botao"
					action="#{manterSituacaoTributariaBean.criarEntidade}" ajax="false"
					rendered="#{p:ifGranted('CRIAR_SITUACAOTRIBUTARIA')}"
					title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterSituacaoTributariaBean.preRenderList}" />
		<h:form id="formListaSituacoesTributaria" prependId="false">

			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">
				<p:panelGrid columns="6" styleClass="full-width">
					<p:outputLabel value="#{rsc.label_situacaoTributaria}"
						for="acSituacaoTributaria" />

					<p:outputLabel value="#{rsc.label_codigoSituacaoTributaria}"
						for="txtCodigoSituacaoTributaria" />

					<p:outputLabel value="#{rsc.label_tipoImposto}"
						for="cmbTipoImposto" />

					<p:outputLabel value="#{rsc.label_ativo}" for="cmbAtivo" />

					<p:outputLabel value="#{rsc.label_situacaoPadrao}" for="cmbPadrao" />

					<p:spacer />

					<p:autoComplete id="acSituacaoTributaria" minQueryLength="3"
						value="#{manterSituacaoTributariaBean.filtro.nome}" effect="fade"
						maxResults="7" size="30"
						completeMethod="#{manterSituacaoTributariaBean.autoCompleteNome}">
						<p:ajax event="change" process="@form"
							listener="#{manterSituacaoTributariaBean.buscarPorFiltros}"
							update="listaSituacoesTributaria" />
					</p:autoComplete>

					<p:inputText label="#{rsc.label_codigoTipoImposto}"
						id="txtCodigoSituacaoTributaria" styleClass="numerico4" size="7"
						title="#{rsc.label_codigoTipoImposto}"
						value="#{manterSituacaoTributariaBean.filtro.codigo}" />

					<p:selectOneMenu label="#{rsc.label_tipoImposto}"
						value="#{manterSituacaoTributariaBean.filtro.tipoImposto}"
						id="cmbTipoImposto">
						<p:ajax event="change" process="@form"
							listener="#{manterSituacaoTributariaBean.buscarPorFiltros}"
							update="listaSituacoesTributaria" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems
							value="#{manterSituacaoTributariaBean.formulario.tiposImposto}"
							var="c" itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:selectOneMenu label="#{rsc.label_ativo}"
						value="#{manterSituacaoTributariaBean.filtro.ativo}" id="cmbAtivo">
						<p:ajax event="change" process="@form"
							listener="#{manterSituacaoTributariaBean.buscarPorFiltros}"
							update="listaSituacoesTributaria" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterSituacaoTributariaBean.status}"
							var="c" itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:selectOneMenu label="#{rsc.label_situacaoPadrao}"
						value="#{manterSituacaoTributariaBean.filtro.padrao}"
						id="cmbPadrao">
						<p:ajax event="change"
							listener="#{manterSituacaoTributariaBean.buscarPorFiltros}"
							update="listaSituacoesTributaria" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems value="#{manterSituacaoTributariaBean.status}"
							var="c" itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listaSituacoesTributaria"
						actionListener="#{manterSituacaoTributariaBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />
				</p:panelGrid>
			</p:fieldset>
			<p:watermark value="#{rsc.wm_nomeSituacaoTributaria}"
				for="acSituacaoTributaria" />
			<p:watermark value="#{rsc.wm_codigo}"
				for="txtCodigoSituacaoTributaria" />

			<p:panel id="pnlListaSituacoesTributarias"
				header="#{rsc.label_situacoesTributariasCadastradas}"
				toggleable="true" toggleSpeed="500">

				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="situacaoTributaria" id="listaSituacoesTributaria"
						value="#{manterSituacaoTributariaBean.entidades}" paginator="true"
						rows="10" paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">

						<p:column headerText="#{rsc.label_codigo}"
							sortBy="#{situacaoTributaria.codigo}" styleClass="centralizado">
							<p:outputLabel value="#{situacaoTributaria.codigo}" />
						</p:column>

						<p:column headerText="#{rsc.label_nomeSituacaoTributaria}"
							sortBy="#{situacaoTributaria.nome}">
							<p:outputLabel value="#{situacaoTributaria.nome}" />
						</p:column>


						<p:column headerText="#{rsc.label_tipoImposto}"
							sortBy="#{situacaoTributaria.tipoImposto.label}"
							styleClass="centralizado">
							<p:outputLabel value="#{situacaoTributaria.tipoImposto.label}" />
						</p:column>

						<p:column headerText="#{rsc.label_ativo}"
							sortBy="#{situacaoTributaria.ativo}" styleClass="centralizado">
							<p:outputLabel value="#{rsc.label_sim}"
								rendered="#{situacaoTributaria.ativo}" />
							<p:outputLabel value="#{rsc.label_nao}"
								rendered="#{!situacaoTributaria.ativo}" />
						</p:column>

						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">

							<p:commandButton update=":habilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_SITUACAOTRIBUTARIA') and !situacaoTributaria.ativo}"
								oncomplete="habilitar.show()" icon="ui-icon ui-icon-locked"
								title="#{rsc.label_habilitar}">
								<f:setPropertyActionListener value="#{situacaoTributaria}"
									target="#{manterSituacaoTributariaBean.entidade}" />
							</p:commandButton>

							<p:commandButton update=":desabilitarDialog"
								rendered="#{p:ifGranted('HABILITAR_SITUACAOTRIBUTARIA') and situacaoTributaria.ativo}"
								oncomplete="desabilitar.show()" icon="ui-icon ui-icon-unlocked"
								title="#{rsc.label_desabilitar}">
								<f:setPropertyActionListener value="#{situacaoTributaria}"
									target="#{manterSituacaoTributariaBean.entidade}" />
							</p:commandButton>

							<p:commandButton icon="ui-icon ui-icon-pencil"
								rendered="#{p:ifGranted('ALTERAR_SITUACAOTRIBUTARIA')}"
								title="#{rsc.label_editar}" ajax="false"
								action="editarSituacaoTributaria">
								<f:setPropertyActionListener value="#{situacaoTributaria}"
									target="#{manterSituacaoTributariaBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
		</h:form>

		<p:dialog id="detalharDialog" header="#{rsc.label_detalhar}"
			widgetVar="detalhar" width="520">
			<p:panelGrid columns="2" cellspacing="4" id="situacaoTributariaData">
				<p:outputLabel value="#{rsc.label_codigoSituacaoTributaria}"
					style="font-weight: bold;" />
				<p:outputLabel
					value="#{manterSituacaoTributariaBean.entidade.codigo}" />
				<p:outputLabel value="#{rsc.label_nomeSituacaoTributaria}"
					style="font-weight: bold;" />
				<p:outputLabel value="#{manterSituacaoTributariaBean.entidade.nome}" />
			</p:panelGrid>
		</p:dialog>

		<p:confirmDialog message="#{msg.questionConfirmaHabilitar}"
			appendTo="@(body)" width="250" id="habilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="habilitar">
			<h:form id="habilitarForm">
				<p:commandButton value="#{rsc.label_sim}" styleClass="botao"
					actionListener="#{manterSituacaoTributariaBean.habilitar}"
					oncomplete="habilitar.hide();"
					update=":formListaSituacoesTributaria:listaSituacoesTributaria" />
				<p:commandButton value="#{rsc.label_nao}" onclick="habilitar.hide()"
					styleClass="botao" />
			</h:form>
		</p:confirmDialog>

		<p:confirmDialog message="#{msg.questionConfirmaDesabilitar}"
			appendTo="@(body)" width="250" id="desabilitarDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="desabilitar">
			<h:form id="desabilitarForm">
				<p:commandButton value="#{rsc.label_sim}" styleClass="botao"
					actionListener="#{manterSituacaoTributariaBean.desabilitar}"
					oncomplete="desabilitar.hide()"
					update=":formListaSituacoesTributaria:listaSituacoesTributaria" />
				<p:commandButton value="#{rsc.label_nao}"
					onclick="desabilitar.hide()" styleClass="botao" />
			</h:form>
		</p:confirmDialog>


	</ui:define>
</ui:composition>

